import * as Cesium from "cesium/Cesium";

import VectorLayer from "../../src/layer/vector/VectorLayer"; 
import Polyline from "../../src/overlay/entity/Polyline";
import { LayerEventType, OverlayEventType } from "../../src/event/EventType";
import Point from "../../src/overlay/entity/Point";
import EntitySource from "../../src/data/source/vector/EntitySource";

export function add_layer_entity(earth){

    let source = new EntitySource("vector");
    let layer = new VectorLayer("vector", {
        source : source
    });

    layer.on(LayerEventType.ADD, evt=>{
        console.log(evt.obj.name);
    });

    let  val  =3;
    
    earth.addLayer(layer);

    let entity = undefined;
    entity = add_entity_point(layer);
    //entity = add_entity_polyline(layer);

    entity.on(OverlayEventType.CLICK, evt=>{
        console.log("[Entity Click]:" + evt.obj.id);
    });
    

    earth.zoomTo(entity);
}

function add_entity_point(layer){
    let position = {
        lng : 116.0,
        lat : 39.0,
        alt : 0
    };

    let entity = new Point(position);
    layer.addOverlay(entity);

    return entity;
}

function add_entity_polyline(layer){
    
    let coordiates = [
        // lng, lat, alt
        116.14458984774065,
        40.30602839249214,
        0,
        116.1934975247693,
        40.30185115488014,
        0,
        116.21759905683979,
        40.299040985998055,
        0,
        116.22622724920136,
        40.28964653405332,
        0,
        116.23729779430624,
        40.27389302668485,
        0,
    ];

    let options = {
        clampToGround: true,
        // 线宽
        width: 10.0,
        // 材质
        material: Cesium.Color.RED,
    };

    let polyline = new Polyline(coordiates, options);
    layer.addOverlay(polyline);    
 
    return polyline;
}